import 'package:syria_sports/data/models/error_model.dart';

import '../apiClient/api_client.dart';
import '../apiClient/api_keys.dart';
import '../models/auth/user.dart';
import '../models/data.dart';
import '../remote/dio_helper.dart';

class AuthController {
  static Future<Data?> login({
    String? usernameOrEmail,
    String? password,
    String? barcode,
  }) async {
    var res = await DioHelper.postData(
      url: ApiClient.login,
      data: {
        ApiKeys.email: usernameOrEmail,
        ApiKeys.password: password,
        ApiKeys.barcode: barcode,
      },
    );
    if (res == null) return null;

    if (res.statusCode != 200) {
      ErrorModel.fromResponse(res);
      return null;
    } else {
      print(res.data);
    }
    Data response = Data.fromJson(res.data);
    return response;
  }
}
